package com.hcy.service;

import com.hcy.entity.Baidu;
import com.hcy.reasult.Result;
import com.hcy.utils.SpiderUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description:
 * @Author: LiJun
 * @Date: 2025/7/23 15:19
 */
@Service
@Slf4j
public class HotService {
    @Autowired
    private RedisTemplate redisTemplate;

    public Result getBaiduHot() {
        List<Baidu> baiduList = (List<Baidu>) redisTemplate.opsForValue().get("baiduList");
        if (baiduList == null) {
            List<Baidu> baiduList1 = SpiderUtil.spiderBaidu();
            return Result.success(baiduList1);
        }
        else {
            return Result.success(baiduList);
        }
    }
}
